package com.lzx.guanchajava.pojo.bean.topicList

import android.view.View
import com.lzx.guanchajava.util.App
import com.lzx.guanchajava.util.ImageUtils
import com.lzx.guanchajava.util.JumpUtil
import com.lzx.guanchajava.view.activity.NewsActivity
import com.lzx.guanchajava.view.activity.PostActivity
import com.lzx.guanchajava.pojo.bean.postTopicList.Data
import com.lzx.guanchajava.util.ActivityStatic

data class TopicItem(
        val access_device: Int,
        val code_type: Int,
        val collection_count: String,
        val comment_count: Int,
        val created_at: String,
        val has_collection: Boolean,
        val has_praise: Boolean,
        val has_vote: Boolean,
        val id: Int,
        val is_anonymous: Boolean,
        val orderby_value: Int,
        val pass_at: String,
        val pic: String,
        val post_url: String,
        val post_url_night: String,
        val praise_num: Int,
        val share_url: String,
        val status: Int,
        val summary: String,
        val title: String,
        val topics: MutableList<Topic>,
        val user_description: String,
        val user_id: Int,
        val user_level: String,
        val user_level_logo: String,
        val user_nick: String,
        val user_photo: String,
        val view_count: Int
) {
    fun onClick(id: String, type: String) {
        if (type == "1") JumpUtil.startActivity(ActivityStatic.getInstance().activity, NewsActivity::class.java, "ID" to id, "CODETYPE" to type)
        else JumpUtil.startActivity(ActivityStatic.getInstance().activity, PostActivity::class.java, "ID" to id, "CODETYPE" to type)

    }

    fun onLongClick(imageUtil: String, view: View) {
        ImageUtils.saveImageWithPopup(imageUtil,view)
    }

    companion object {
        fun fromData(data: Data): TopicItem {
            return TopicItem(
                    data.access_device,
                    data.code_type,
                    data.collection_count,
                    data.comment_count,
                    data.created_at,
                    data.has_collection,
                    data.has_praise,
                    data.has_vote,
                    data.id,
                    data.is_anonymous,
                    data.orderby_value,
                    data.pass_at,
                    data.pic,
                    data.post_url,
                    data.post_url_night,
                    data.praise_num,
                    data.share_url,
                    data.status,
                    data.summary,
                    data.title,
                    data.topics as MutableList<Topic>,
                    data.user_description,
                    data.user_id,
                    data.user_level,
                    data.user_level_logo,
                    data.user_nick,
                    data.user_photo,
                    data.view_count
            )
        }
    }
}